import 'dart:convert';
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:lepig/model/PageInfoModel.dart';
import 'package:lepig/model/ProductModel.dart';
import 'package:lepig/model/SelectProductTypeModel.dart';
import 'package:lepig/request/lib/HttpManager.dart';

import 'lib/NWApi.dart';
import 'lib/NWMethod.dart';

/**
 * 获取分类
 */

class SelectProductsParams{
    String q;
    String cid="";
    String isCoupon="";
    String sort="";
    String pageSize="10";
    String pageNum="1";
}


// ignore: non_constant_identifier_names
Future<List<ProductModel>> HttpSelectProducts(BuildContext context,{SelectProductsParams params}) async {
  List<ProductModel> lists = new List<ProductModel>();
  Map<String, dynamic> data =new Map() ;
  data["q"] =params.q;
  data["cid"] =params.cid;
  data["isCoupon"] =params.isCoupon;
  data["sort"] = params.sort;
  data["pageSize"] = params.pageSize;
  data["pageNum"] = params.pageNum;
  print(data.values.toString());
  Map responseBody = await HttpManager()
      .request(NWApi.selectTypeProducts, NWMethod.POST,params: data,context: context);
  PageInfoModel infoModel = PageInfoModel.fromJson(responseBody);
  List<dynamic> list = responseBody['data']["list"];
  list.forEach((element) {
    lists.add(ProductModel.fromJson(element));
  });
  return lists;
}
